package com.ruoyi.labdata.service.impl;

import java.text.ParseException;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.stream.Collectors;

import javax.annotation.Resource;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.ruoyi.common.constant.HttpStatus;
import com.ruoyi.common.core.page.PageDomain;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.core.page.TableSupport;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.course.domain.LabCourse;
import com.ruoyi.course.domain.LabCourseDate;
import com.ruoyi.course.domain.LabCourseTimetable;
import com.ruoyi.course.service.ILabCourseTimetableService;
import com.ruoyi.labdata.domain.LabHolidayReservation;
import com.ruoyi.labdata.domain.LabHolidayReservationStatistics;
import com.ruoyi.labdata.domain.LabReservation;
import com.ruoyi.labdata.mapper.LabHolidayReservationMapper;
import com.ruoyi.labdata.mapper.LabReservationMapper;
import com.ruoyi.labdata.service.ILabHolidayReservationService;
import com.ruoyi.system.utils.SysDateUtils;
import com.ruoyi.system.utils.VacationDayCalculate;
import com.ruoyi.utils.LockUtil;

import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.ObjectUtil;

/**
 * 实验室是否可预约Service业务层处理
 *
 * @author jun.wang
 * @date 2022-04-15
 */
@Service
public class LabHolidayReservationServiceImpl implements ILabHolidayReservationService {
	@Resource
	private LabHolidayReservationMapper labHolidayReservationMapper;

	@Resource
	private LabReservationMapper labReservationMapper;

	private static String lesson = "课";

	private static String advance = "预";

	private static String prohibition = "禁";
	@Autowired
	private ILabCourseTimetableService timetableService;

	@Autowired
	private LockUtil lockUtil;

	/**
	 * 查询实验室是否可预约
	 *
	 * @param dayId
	 *            实验室是否可预约ID
	 * @return 实验室是否可预约
	 */
	@Override
	public LabHolidayReservation selectLabHolidayReservationById(Long dayId) {
		return labHolidayReservationMapper.selectLabHolidayReservationById(dayId);
	}

	/**
	 * 查询实验室是否可预约列表
	 *
	 * @param labHolidayReservation
	 *            实验室是否可预约
	 * @return 实验室是否可预约
	 */
	@Override
	public List<LabHolidayReservation> selectLabHolidayReservationList(LabHolidayReservation labHolidayReservation) {
		if (!ObjectUtil.isNull(labHolidayReservation.getHolidayDate())) {
			Date parse = DateUtil.parse(labHolidayReservation.getHolidayDate(), "yyyy-MM-dd");
			Date dateTime = DateUtil.offsetDay(parse, 0);
			String parse2 = DateUtil.format(dateTime, "yyyy-MM-dd");
			labHolidayReservation.setHolidayDate(parse2);
		}
		return labHolidayReservationMapper.selectLabHolidayReservationList(labHolidayReservation);
	}

	/**
	 * 新增实验室是否可预约
	 *
	 * @param labHolidayReservation
	 *            实验室是否可预约
	 * @return 结果
	 */
	@Deprecated
	@Override
	public int insertLabHolidayReservation(LabHolidayReservation labHolidayReservation) {
		if (labHolidayReservation.getYear() == null) {
			throw new RuntimeException("请输入需要生成工作日的年份!");
		}
		if (labHolidayReservation.getClassRoomId() == null) {
			throw new RuntimeException("请输入需要生成工作日的实验室!");
		}
		boolean lock = lockUtil.lock(getLockKey(labHolidayReservation.getYear().toString()), 1000 * 60);
		if (!lock) {
			throw new RuntimeException("系统忙请稍后生成!");
		}
		Integer isExist = labHolidayReservationMapper.checkLabDate(labHolidayReservation.getYear().toString(),
				labHolidayReservation.getClassRoomId());
		if (isExist != null && isExist > 0) {
			throw new RuntimeException("此实验室该年份工作日已经存在，不能再生成!");
		}
		HashMap<String, VacationDayCalculate.OffDay> map = new VacationDayCalculate()
				.yearVacationDay(labHolidayReservation.getYear());
		Set<String> keySet = map.keySet();
		Date currentDate = DateUtils.getNowDate();
		for (String key : keySet) {
			VacationDayCalculate.OffDay v = map.get(key);
			LabHolidayReservation labHolidayReservationNew = new LabHolidayReservation();

			labHolidayReservationNew.setCreateTime(currentDate);
			labHolidayReservationNew.setCreateBy(SecurityUtils.getUsername());
			labHolidayReservationNew.setHolidayDate(labHolidayReservation.getYear() + "-" + key);
			labHolidayReservationNew.setHolidayName(v.getRemark());
			// 节日标识(0-节假日 1-工作日)
			labHolidayReservationNew.setHolidayFlag(v.isFlag() ? "0" : "1");
			// 设置如果是节假日 则实验室不可预约为1 可预约为0
			labHolidayReservationNew.setSectionOne(v.isFlag() ? 1 : 0);
			labHolidayReservationNew.setSectionTwo(v.isFlag() ? 1 : 0);
			labHolidayReservationNew.setSectionThree(v.isFlag() ? 1 : 0);
			labHolidayReservationNew.setSectionFour(v.isFlag() ? 1 : 0);
			labHolidayReservationNew.setSectionFive(v.isFlag() ? 1 : 0);
			labHolidayReservationNew.setSectionSix(v.isFlag() ? 1 : 0);
			labHolidayReservationNew.setSectionSeven(v.isFlag() ? 1 : 0);
			labHolidayReservationNew.setSectionEight(v.isFlag() ? 1 : 0);
			labHolidayReservationNew.setSectionNine(v.isFlag() ? 1 : 0);
			labHolidayReservationNew.setSectionTen(v.isFlag() ? 1 : 0);
			labHolidayReservationNew.setSectionEleven(v.isFlag() ? 1 : 0);
			labHolidayReservationNew.setSectionTwelve(v.isFlag() ? 1 : 0);
			labHolidayReservationNew.setClassRoomId(labHolidayReservation.getClassRoomId());
			labHolidayReservationMapper.insertLabHolidayReservation(labHolidayReservationNew);
		}
		lockUtil.unLock(getLockKey(labHolidayReservation.getYear().toString()));
		return 1;

	}

	public int generalCalendarDate(LabCourseTimetable timeTable, Long labId) {
		
		boolean lock = lockUtil.lock(getLockKey("labId"+labId), 1000 * 60);
		if (!lock) {
			throw new RuntimeException("系统忙请稍后处理!");
		}
		try{

			String startDate = DateUtils.parseDateToStr("yyyy-MM-dd", timeTable.getCourseStartDate());
			Integer isExist = labHolidayReservationMapper.checkLabDate(startDate, labId);
			if (isExist != null && isExist > 0) {
				return 1;
			}
			Date currentDate = DateUtils.getNowDate();
			String startYear = startDate.substring(0,4);
			generalCourseCalendar(timeTable, labId, currentDate, startYear);
			String endYear = DateUtils.parseDateToStr("yyyy", timeTable.getLastDate());
			if(!startYear.equals(endYear)){
				generalCourseCalendar(timeTable, labId, currentDate, endYear);
			}
		}finally{
			lockUtil.unLock(getLockKey("labId"+labId));
		}
		return 1;

	}

	private void generalCourseCalendar(LabCourseTimetable timeTable, Long labId, Date currentDate, String year) {
		HashMap<String, VacationDayCalculate.OffDay> map = new VacationDayCalculate()
				.yearVacationDay(Integer.valueOf(year));
		Set<String> keySet = map.keySet();
		for (String key : keySet) {
			String dateStr = year + "-" + key;
			Date date = DateUtils.parseDate(dateStr);
			if(date.before(timeTable.getCourseStartDate())||date.after(timeTable.getLastDate())){
				continue;
			}
			VacationDayCalculate.OffDay v = map.get(key);
			LabHolidayReservation labHolidayReservationNew = new LabHolidayReservation();
			labHolidayReservationNew.setWeekNum(SysDateUtils.getCourseWeekNum(timeTable.getCourseStartDate(), date));
			labHolidayReservationNew.setCreateTime(currentDate);
			labHolidayReservationNew.setCreateBy(SecurityUtils.getUsername());
			labHolidayReservationNew.setHolidayDate(dateStr);
			labHolidayReservationNew.setHolidayName(v.getRemark());
			// 节日标识(0-节假日 1-工作日)
			labHolidayReservationNew.setHolidayFlag(v.isFlag() ? "0" : "1");
			// 设置如果是节假日 则实验室不可预约为1 可预约为0
			labHolidayReservationNew.setSectionOne(v.isFlag() ? 1 : 0);
			labHolidayReservationNew.setSectionTwo(v.isFlag() ? 1 : 0);
			labHolidayReservationNew.setSectionThree(v.isFlag() ? 1 : 0);
			labHolidayReservationNew.setSectionFour(v.isFlag() ? 1 : 0);
			labHolidayReservationNew.setSectionFive(v.isFlag() ? 1 : 0);
			labHolidayReservationNew.setSectionSix(v.isFlag() ? 1 : 0);
			labHolidayReservationNew.setSectionSeven(v.isFlag() ? 1 : 0);
			labHolidayReservationNew.setSectionEight(v.isFlag() ? 1 : 0);
			labHolidayReservationNew.setSectionNine(v.isFlag() ? 1 : 0);
			labHolidayReservationNew.setSectionTen(v.isFlag() ? 1 : 0);
			labHolidayReservationNew.setSectionEleven(v.isFlag() ? 1 : 0);
			labHolidayReservationNew.setSectionTwelve(v.isFlag() ? 1 : 0);
			labHolidayReservationNew.setClassRoomId(labId);
			labHolidayReservationMapper.insertLabHolidayReservation(labHolidayReservationNew);
		}
	}

	@Transactional
	public void doReservation(LabCourse labCourse) {
		boolean lock = lockUtil.lock(getLockKey("labID"+labCourse.getLabId()), 1000 * 60);
		if (!lock) {
			throw new RuntimeException("系统忙请稍后处理!");
		}
		try{
			List<LabCourseDate> reservationDateList = labCourse.getCourseDateList();
			// 判断此预约日期是否可以预约
			LabHolidayReservation query = new LabHolidayReservation();
			query.setClassRoomId(labCourse.getLabId());
			List<String> queryDateList =  new ArrayList<String>();
			for (LabCourseDate labCourseDate : reservationDateList) {
				queryDateList.add(DateUtils.parseDateToStr("yyyy-MM-dd",labCourseDate.getCourseDate()));
			}
			if(queryDateList.size()>0){
				query.setWorkDateList(queryDateList);
			}
			List<LabHolidayReservation> workDayList = labHolidayReservationMapper.selectLabHolidayReservationList(query);
			if (workDayList == null || workDayList.size() == 0) {
				// 生成当年的预定日期
				LabCourseTimetable timeTable;
				timeTable = timetableService.getDefaultTimetable(reservationDateList.get(0).getCourseDate());
				generalCalendarDate( timeTable, labCourse.getLabId());
				
				
				workDayList = labHolidayReservationMapper.selectLabHolidayReservationList(query);
			}
			StringBuffer totalErro = new StringBuffer();
			for (LabHolidayReservation labHolidayReservation : workDayList) {
				List<Integer> sectionList = new ArrayList<Integer>();
				for (LabCourseDate labCourseDate : reservationDateList) {
					String dateStr = DateUtils.parseDateToStr("yyyy-MM-dd",labCourseDate.getCourseDate());
					if(dateStr.equals(labHolidayReservation.getHolidayDate())){
						if(labCourseDate.getSectionList()!=null){
							sectionList = labCourseDate.getSectionList();
						}else{
							for(int i=labCourseDate.getSectionStart();i<=labCourseDate.getSectionEnd();i++){
								sectionList.add(i);
							}
						}
						break;
					}
				}
				boolean isWorkday = labHolidayReservation.getHolidayFlag().equals("1");
				// 获取开始节次和结束节次
				StringBuffer erroInfo = new StringBuffer();
				for (Integer i : sectionList) {
					switch (i) {
					case 1: {
						if (isWorkday && labHolidayReservation.getSectionOne() == 1) {
							erroInfo.append(i).append(",");
						} else {
							labHolidayReservation.setSectionOne(1);
						}
						break;
					}
					case 2: {
						if (isWorkday && labHolidayReservation.getSectionTwo() == 1) {
							erroInfo.append(i).append(",");
						} else {
							labHolidayReservation.setSectionTwo(1);
						}
						break;
					}
					case 3: {
						if (isWorkday && labHolidayReservation.getSectionThree() == 1) {
							erroInfo.append(i).append(",");
						} else {
							labHolidayReservation.setSectionThree(1);
						}
						break;
					}
					case 4: {
						if (isWorkday && labHolidayReservation.getSectionFour() == 1) {
							erroInfo.append(i).append(",");
						} else {
							labHolidayReservation.setSectionFour(1);
						}
						break;
					}
					case 5: {
						if (isWorkday && labHolidayReservation.getSectionFive() == 1) {
							erroInfo.append(i).append(",");
						} else {
							labHolidayReservation.setSectionFive(1);
						}
						break;
					}
					case 6: {
						if (isWorkday && labHolidayReservation.getSectionSix() == 1) {
							erroInfo.append(i).append(",");
						} else {
							labHolidayReservation.setSectionSix(1);
						}
						break;
					}
					case 7: {
						if (isWorkday && labHolidayReservation.getSectionSeven() == 1) {
							erroInfo.append(i).append(",");
						} else {
							labHolidayReservation.setSectionSeven(1);
						}
						break;
					}
					case 8: {
						if (isWorkday && labHolidayReservation.getSectionEight() == 1) {
							erroInfo.append(i).append(",");
						} else {
							labHolidayReservation.setSectionEight(1);
						}
						break;
					}
					case 9: {
						if (isWorkday && labHolidayReservation.getSectionNine() == 1) {
							erroInfo.append(i).append(",");
						} else {
							labHolidayReservation.setSectionNine(1);
						}
						break;
					}
					case 10: {
						if (isWorkday && labHolidayReservation.getSectionTen() == 1) {
							erroInfo.append(i).append(",");
						} else {
							labHolidayReservation.setSectionTen(1);
						}
						break;
					}
					case 11: {
						if (isWorkday && labHolidayReservation.getSectionEleven() == 1) {
							erroInfo.append(i).append(",");
						} else {
							labHolidayReservation.setSectionEleven(1);
						}
						break;
					}
					case 12: {
						if (isWorkday && labHolidayReservation.getSectionTwelve() == 1) {
							erroInfo.append(i).append(",");
						} else {
							labHolidayReservation.setSectionTwelve(1);
						}
						break;
					}
					}
				}
				if (erroInfo.length() > 0) {
					totalErro.append("日期:" + labHolidayReservation.getHolidayDate()+", 周次:"+labCourse.getWeekOpenNums()+", 课程 :"+labCourse.getCourseName()+", 实验项目:"+labCourse.getExperimentalProject()+", ").append("节次:").append(erroInfo)
							.append(";");
				} else {
					if (!isWorkday) {
						labHolidayReservation.setHolidayFlag("1");
					}
				}
			}
			if (totalErro.length() > 0) {
				throw new RuntimeException("错误：实验室已经被预定过,预定信息，" + totalErro);
			} else {
				for (LabHolidayReservation labHolidayReservation : workDayList) {
					labHolidayReservationMapper.updateLabHolidayReservation(labHolidayReservation);
				}
			}
		}finally{
			lockUtil.unLock(getLockKey("labID"+labCourse.getLabId()));
		}
	}

	@Transactional
	public void cancelReservation(LabCourse labCourse) {
		List<LabCourseDate> reservationDateList = labCourse.getCourseDateList();
		// 判断此预约日期是否可以预约
		LabHolidayReservation query = new LabHolidayReservation();
		query.setClassRoomId(labCourse.getLabId());
		query.setWorkDateList(new ArrayList<String>());
		for (LabCourseDate labCourseDate : reservationDateList) {
			query.getWorkDateList().add(DateUtils.parseDateToStr("yyyy-MM-dd",labCourseDate.getCourseDate()));
		}
		List<LabHolidayReservation> workDayList = labHolidayReservationMapper.selectLabHolidayReservationList(query);
		// 获取开始节次和结束节次
		Integer start = 0;//labCourse.getSectionStart() - 1;
		Integer end = 0;//labCourse.getSectionEnd();
		for (LabHolidayReservation labHolidayReservation : workDayList) {
			List<Integer> sectionList = new ArrayList<Integer>();
			for (LabCourseDate labCourseDate : reservationDateList) {
				String dateStr = DateUtils.parseDateToStr("yyyy-MM-dd",labCourseDate.getCourseDate());
				if(dateStr.equals(labHolidayReservation.getHolidayDate())){
					if(labCourseDate.getSectionList()!=null){
						sectionList = labCourseDate.getSectionList();
					}else{
						for(int i=labCourseDate.getSectionStart();i<=labCourseDate.getSectionEnd();i++){
							sectionList.add(i);
						}
					}
					break;
				}
			}
			for (Integer i : sectionList) {
				switch (i) {
				case 0: {
					labHolidayReservation.setSectionOne(0);
					break;
				}
				case 1: {
					labHolidayReservation.setSectionTwo(0);
					break;
				}
				case 2: {
					labHolidayReservation.setSectionThree(0);
					break;
				}
				case 3: {
					labHolidayReservation.setSectionFour(0);
					break;
				}
				case 4: {
					labHolidayReservation.setSectionFive(0);
					break;
				}
				case 5: {
					labHolidayReservation.setSectionSix(0);
					break;
				}
				case 6: {
					labHolidayReservation.setSectionSeven(0);
					break;
				}
				case 7: {
					labHolidayReservation.setSectionEight(0);
					break;
				}
				case 8: {
					labHolidayReservation.setSectionNine(0);
					break;
				}
				case 9: {
					labHolidayReservation.setSectionTen(0);
					break;
				}
				case 10: {
					labHolidayReservation.setSectionEleven(0);
					break;
				}
				case 11: {
					labHolidayReservation.setSectionTwelve(0);
				}
				}
			}
		}
		for (LabHolidayReservation labHolidayReservation : workDayList) {
			labHolidayReservationMapper.updateLabHolidayReservation(labHolidayReservation);
		}

	}

	/**
	 * 修改实验室是否可预约
	 *
	 * @param labHolidayReservation
	 *            实验室是否可预约
	 * @return 结果
	 */
	@Override
	public int updateLabHolidayReservation(LabHolidayReservation labHolidayReservation) {
		return labHolidayReservationMapper.updateLabHolidayReservation(labHolidayReservation);
	}

	/**
	 * 批量删除实验室是否可预约
	 *
	 * @param dayIds
	 *            需要删除的实验室是否可预约ID
	 * @return 结果
	 */
	@Override
	public int deleteLabHolidayReservationByIds(Long[] dayIds) {
		return labHolidayReservationMapper.deleteLabHolidayReservationByIds(dayIds);
	}

	/**
	 * 删除实验室是否可预约信息
	 *
	 * @param dayId
	 *            实验室是否可预约ID
	 * @return 结果
	 */
	@Override
	public int deleteLabHolidayReservationById(Long dayId) {
		return labHolidayReservationMapper.deleteLabHolidayReservationById(dayId);
	}

	@Override
	public TableDataInfo listLabReservationStatistics(LabHolidayReservation labHolidayReservation) {
		PageDomain pageDomain = TableSupport.buildPageRequest();
		Integer pageNum = pageDomain.getPageNum();
		Integer pageSize = pageDomain.getPageSize();

		TableDataInfo rspData = new TableDataInfo();

		List<LabHolidayReservationStatistics> list = new ArrayList<>();
		if (!ObjectUtil.isNull(labHolidayReservation.getHolidayDate())) {
			Date parse = DateUtil.parse(labHolidayReservation.getHolidayDate(), "yyyy-MM-dd");
			Date dateTime = DateUtil.offsetDay(parse, 0);
			String parse2 = DateUtil.format(dateTime, "yyyy-MM-dd");
			labHolidayReservation.setHolidayDate(parse2);
		}
		// 获取符合条件的实验室预约记录日历
		PageHelper.startPage(pageNum, pageSize, null);
		List<LabHolidayReservation> labHolidayReservations = labHolidayReservationMapper
				.selectLabHolidayReservationList(labHolidayReservation);
		rspData.setTotal(new PageInfo<LabHolidayReservation>(labHolidayReservations).getTotal());
		List<String> holidayDateList = labHolidayReservations.stream().map(LabHolidayReservation::getHolidayDate)
				.collect(Collectors.toList());
		if (ObjectUtil.isNotNull(holidayDateList) && holidayDateList.size() > 1) {
			// 获取审批通过的实验室预约记录
			List<LabReservation> labReservations = labReservationMapper
					.selectLabReservationListByHolidayDateList(holidayDateList, labHolidayReservation.getClassRoomId());
			Map<Date, List<LabReservation>> collect = labReservations.stream()
					.collect(Collectors.groupingBy(LabReservation::getCourseDate));
			for (LabHolidayReservation holidayReservation : labHolidayReservations) {
				LabHolidayReservationStatistics labHolidayReservationStatistics = new LabHolidayReservationStatistics();
				labHolidayReservationStatistics.setHolidayDate(holidayReservation.getHolidayDate());
				labHolidayReservationStatistics.setHolidayName(holidayReservation.getHolidayName());
				labHolidayReservationStatistics.setHolidayFlag(holidayReservation.getHolidayFlag());
				labHolidayReservationStatistics.setHolidayFlag(holidayReservation.getHolidayFlag());
				labHolidayReservationStatistics.setClassRoomId(holidayReservation.getClassRoomId());
				HashMap<Integer, LabHolidayReservationStatistics> map = new HashMap<>();
				if ("0".equals(holidayReservation.getHolidayFlag())) {
					// 节假日
					setBasicData(map, prohibition);
				} else {
					// 工作日
					setBasicData(map, advance);
				}
				String holidayDate = holidayReservation.getHolidayDate();
				Date parse = DateUtil.parse(holidayDate, "yyyy-MM-dd");
				List<LabReservation> labReservations1 = collect.get(parse);
				if (CollUtil.isEmpty(labReservations1)) {
					labReservations1 = new ArrayList<>();
				}
				for (LabReservation labReservation : labReservations1) {
					Integer start = labReservation.getSectionStart();
					Integer end = labReservation.getSectionEnd();
					for (int i = start; i <= end; i++) {
						if (i == 1) {
							LabHolidayReservationStatistics labHolidayReservationStatistics1 = map.get(i);
							labHolidayReservationStatistics1.setAppointmentTypeOne(lesson);
							Long number = labHolidayReservationStatistics1.getAppointmentNumberOne()
									+ labReservation.getReserveSeats();
							labHolidayReservationStatistics1.setAppointmentNumberOne(number);
						} else if (i == 2) {
							LabHolidayReservationStatistics labHolidayReservationStatistics2 = map.get(i);
							labHolidayReservationStatistics2.setAppointmentTypeTwo(lesson);
							Long number = labHolidayReservationStatistics2.getAppointmentNumberTwo()
									+ labReservation.getReserveSeats();
							labHolidayReservationStatistics2.setAppointmentNumberTwo(number);
						} else if (i == 3) {
							LabHolidayReservationStatistics labHolidayReservationStatistics3 = map.get(i);
							labHolidayReservationStatistics3.setAppointmentTypeThree(lesson);
							Long number = labHolidayReservationStatistics3.getAppointmentNumberThree()
									+ labReservation.getReserveSeats();
							labHolidayReservationStatistics3.setAppointmentNumberThree(number);
						} else if (i == 4) {
							LabHolidayReservationStatistics labHolidayReservationStatistics4 = map.get(i);
							labHolidayReservationStatistics4.setAppointmentTypeFour(lesson);
							Long number = labHolidayReservationStatistics4.getAppointmentNumberFour()
									+ labReservation.getReserveSeats();
							labHolidayReservationStatistics4.setAppointmentNumberFour(number);
						} else if (i == 5) {
							LabHolidayReservationStatistics labHolidayReservationStatistics5 = map.get(i);
							labHolidayReservationStatistics5.setAppointmentTypeFive(lesson);
							Long number = labHolidayReservationStatistics5.getAppointmentNumberFive()
									+ labReservation.getReserveSeats();
							labHolidayReservationStatistics5.setAppointmentNumberFive(number);
						} else if (i == 6) {
							LabHolidayReservationStatistics labHolidayReservationStatistics6 = map.get(i);
							labHolidayReservationStatistics6.setAppointmentTypeSix(lesson);
							Long number = labHolidayReservationStatistics6.getAppointmentNumberSix()
									+ labReservation.getReserveSeats();
							labHolidayReservationStatistics6.setAppointmentNumberSix(number);
						} else if (i == 7) {
							LabHolidayReservationStatistics labHolidayReservationStatistics7 = map.get(i);
							labHolidayReservationStatistics7.setAppointmentTypeSeven(lesson);
							Long number = labHolidayReservationStatistics7.getAppointmentNumberSeven()
									+ labReservation.getReserveSeats();
							labHolidayReservationStatistics7.setAppointmentNumberSeven(number);
						} else if (i == 8) {
							LabHolidayReservationStatistics labHolidayReservationStatistics8 = map.get(i);
							labHolidayReservationStatistics8.setAppointmentTypeEight(lesson);
							Long number = labHolidayReservationStatistics8.getAppointmentNumberEight()
									+ labReservation.getReserveSeats();
							labHolidayReservationStatistics8.setAppointmentNumberEight(number);
						} else if (i == 9) {
							LabHolidayReservationStatistics labHolidayReservationStatistics9 = map.get(i);
							labHolidayReservationStatistics9.setAppointmentTypeNine(lesson);
							Long number = labHolidayReservationStatistics9.getAppointmentNumberNine()
									+ labReservation.getReserveSeats();
							labHolidayReservationStatistics9.setAppointmentNumberNine(number);
						} else if (i == 10) {
							LabHolidayReservationStatistics labHolidayReservationStatistics10 = map.get(i);
							labHolidayReservationStatistics10.setAppointmentTypeTen(lesson);
							Long number = labHolidayReservationStatistics10.getAppointmentNumberTen()
									+ labReservation.getReserveSeats();
							labHolidayReservationStatistics10.setAppointmentNumberTen(number);
						} else if (i == 11) {
							LabHolidayReservationStatistics labHolidayReservationStatistics11 = map.get(i);
							labHolidayReservationStatistics11.setAppointmentTypeEleven(lesson);
							Long number = labHolidayReservationStatistics11.getAppointmentNumberEleven()
									+ labReservation.getReserveSeats();
							labHolidayReservationStatistics11.setAppointmentNumberEleven(number);
						} else {
							LabHolidayReservationStatistics labHolidayReservationStatistics12 = map.get(i);
							labHolidayReservationStatistics12.setAppointmentTypeTwelve(lesson);
							Long number = labHolidayReservationStatistics12.getAppointmentNumberTwelve()
									+ labReservation.getReserveSeats();
							labHolidayReservationStatistics12.setAppointmentNumberTwelve(number);
						}
					}
				}
				getListResult(list, labHolidayReservationStatistics, map);
			}
		}
		rspData.setRows(list);
		rspData.setCode(HttpStatus.SUCCESS);
		rspData.setMsg("查询成功");
		return rspData;

	}

	// 设置基础数据
	private void setBasicData(HashMap<Integer, LabHolidayReservationStatistics> map, String holidayType) {
		LabHolidayReservationStatistics labHolidayReservationStatistics1 = new LabHolidayReservationStatistics();
		labHolidayReservationStatistics1.setAppointmentTypeOne(holidayType);
		labHolidayReservationStatistics1.setAppointmentNumberOne(0L);
		map.put(1, labHolidayReservationStatistics1);

		LabHolidayReservationStatistics labHolidayReservationStatistics2 = new LabHolidayReservationStatistics();
		labHolidayReservationStatistics2.setAppointmentTypeTwo(holidayType);
		labHolidayReservationStatistics2.setAppointmentNumberTwo(0L);
		map.put(2, labHolidayReservationStatistics2);

		LabHolidayReservationStatistics labHolidayReservationStatistics3 = new LabHolidayReservationStatistics();
		labHolidayReservationStatistics3.setAppointmentTypeThree(holidayType);
		labHolidayReservationStatistics3.setAppointmentNumberThree(0L);
		map.put(3, labHolidayReservationStatistics3);

		LabHolidayReservationStatistics labHolidayReservationStatistics4 = new LabHolidayReservationStatistics();
		labHolidayReservationStatistics4.setAppointmentTypeFour(holidayType);
		labHolidayReservationStatistics4.setAppointmentNumberFour(0L);
		map.put(4, labHolidayReservationStatistics4);

		LabHolidayReservationStatistics labHolidayReservationStatistics5 = new LabHolidayReservationStatistics();
		labHolidayReservationStatistics5.setAppointmentTypeFive(holidayType);
		labHolidayReservationStatistics5.setAppointmentNumberFive(0L);
		map.put(5, labHolidayReservationStatistics5);

		LabHolidayReservationStatistics labHolidayReservationStatistics6 = new LabHolidayReservationStatistics();
		labHolidayReservationStatistics6.setAppointmentTypeSix(holidayType);
		labHolidayReservationStatistics6.setAppointmentNumberSix(0L);
		map.put(6, labHolidayReservationStatistics6);

		LabHolidayReservationStatistics labHolidayReservationStatistics7 = new LabHolidayReservationStatistics();
		labHolidayReservationStatistics7.setAppointmentTypeSeven(holidayType);
		labHolidayReservationStatistics7.setAppointmentNumberSeven(0L);
		map.put(7, labHolidayReservationStatistics7);

		LabHolidayReservationStatistics labHolidayReservationStatistics8 = new LabHolidayReservationStatistics();
		labHolidayReservationStatistics8.setAppointmentTypeEight(holidayType);
		labHolidayReservationStatistics8.setAppointmentNumberEight(0L);
		map.put(8, labHolidayReservationStatistics8);

		LabHolidayReservationStatistics labHolidayReservationStatistics9 = new LabHolidayReservationStatistics();
		labHolidayReservationStatistics9.setAppointmentTypeNine(holidayType);
		labHolidayReservationStatistics9.setAppointmentNumberNine(0L);
		map.put(9, labHolidayReservationStatistics9);

		LabHolidayReservationStatistics labHolidayReservationStatistics10 = new LabHolidayReservationStatistics();
		labHolidayReservationStatistics10.setAppointmentTypeTen(holidayType);
		labHolidayReservationStatistics10.setAppointmentNumberTen(0L);
		map.put(10, labHolidayReservationStatistics10);

		LabHolidayReservationStatistics labHolidayReservationStatistics11 = new LabHolidayReservationStatistics();
		labHolidayReservationStatistics11.setAppointmentTypeEleven(holidayType);
		labHolidayReservationStatistics11.setAppointmentNumberEleven(0L);
		map.put(11, labHolidayReservationStatistics11);

		LabHolidayReservationStatistics labHolidayReservationStatistics12 = new LabHolidayReservationStatistics();
		labHolidayReservationStatistics12.setAppointmentTypeTwelve(holidayType);
		labHolidayReservationStatistics12.setAppointmentNumberTwelve(0L);
		map.put(12, labHolidayReservationStatistics12);
	}

	// 组装数据集合结果
	private void getListResult(List<LabHolidayReservationStatistics> list,
			LabHolidayReservationStatistics labHolidayReservationStatistics,
			HashMap<Integer, LabHolidayReservationStatistics> map) {
		LabHolidayReservationStatistics labHolidayReservationStatistics1 = map.get(1);
		labHolidayReservationStatistics.setAppointmentTypeOne(labHolidayReservationStatistics1.getAppointmentTypeOne());
		labHolidayReservationStatistics
				.setAppointmentNumberOne(labHolidayReservationStatistics1.getAppointmentNumberOne());
		LabHolidayReservationStatistics labHolidayReservationStatistics2 = map.get(2);
		labHolidayReservationStatistics.setAppointmentTypeTwo(labHolidayReservationStatistics2.getAppointmentTypeTwo());
		labHolidayReservationStatistics
				.setAppointmentNumberTwo(labHolidayReservationStatistics2.getAppointmentNumberTwo());
		LabHolidayReservationStatistics labHolidayReservationStatistics3 = map.get(3);
		labHolidayReservationStatistics
				.setAppointmentTypeThree(labHolidayReservationStatistics3.getAppointmentTypeThree());
		labHolidayReservationStatistics
				.setAppointmentNumberThree(labHolidayReservationStatistics3.getAppointmentNumberThree());
		LabHolidayReservationStatistics labHolidayReservationStatistics4 = map.get(4);
		labHolidayReservationStatistics
				.setAppointmentTypeFour(labHolidayReservationStatistics4.getAppointmentTypeFour());
		labHolidayReservationStatistics
				.setAppointmentNumberFour(labHolidayReservationStatistics4.getAppointmentNumberFour());
		LabHolidayReservationStatistics labHolidayReservationStatistics5 = map.get(5);
		labHolidayReservationStatistics
				.setAppointmentTypeFive(labHolidayReservationStatistics5.getAppointmentTypeFive());
		labHolidayReservationStatistics
				.setAppointmentNumberFive(labHolidayReservationStatistics5.getAppointmentNumberFive());
		LabHolidayReservationStatistics labHolidayReservationStatistics6 = map.get(6);
		labHolidayReservationStatistics.setAppointmentTypeSix(labHolidayReservationStatistics6.getAppointmentTypeSix());
		labHolidayReservationStatistics
				.setAppointmentNumberSix(labHolidayReservationStatistics6.getAppointmentNumberSix());
		LabHolidayReservationStatistics labHolidayReservationStatistics7 = map.get(7);
		labHolidayReservationStatistics
				.setAppointmentTypeSeven(labHolidayReservationStatistics7.getAppointmentTypeSeven());
		labHolidayReservationStatistics
				.setAppointmentNumberSeven(labHolidayReservationStatistics7.getAppointmentNumberSeven());
		LabHolidayReservationStatistics labHolidayReservationStatistics8 = map.get(8);
		labHolidayReservationStatistics
				.setAppointmentTypeEight(labHolidayReservationStatistics8.getAppointmentTypeEight());
		labHolidayReservationStatistics
				.setAppointmentNumberEight(labHolidayReservationStatistics8.getAppointmentNumberEight());
		LabHolidayReservationStatistics labHolidayReservationStatistics9 = map.get(9);
		labHolidayReservationStatistics
				.setAppointmentTypeNine(labHolidayReservationStatistics9.getAppointmentTypeNine());
		labHolidayReservationStatistics
				.setAppointmentNumberNine(labHolidayReservationStatistics9.getAppointmentNumberNine());
		LabHolidayReservationStatistics labHolidayReservationStatistics10 = map.get(10);
		labHolidayReservationStatistics
				.setAppointmentTypeTen(labHolidayReservationStatistics10.getAppointmentTypeTen());
		labHolidayReservationStatistics
				.setAppointmentNumberTen(labHolidayReservationStatistics10.getAppointmentNumberTen());
		LabHolidayReservationStatistics labHolidayReservationStatistics11 = map.get(11);
		labHolidayReservationStatistics
				.setAppointmentTypeEleven(labHolidayReservationStatistics11.getAppointmentTypeEleven());
		labHolidayReservationStatistics
				.setAppointmentNumberEleven(labHolidayReservationStatistics11.getAppointmentNumberEleven());
		LabHolidayReservationStatistics labHolidayReservationStatistics12 = map.get(12);
		labHolidayReservationStatistics
				.setAppointmentTypeTwelve(labHolidayReservationStatistics12.getAppointmentTypeTwelve());
		labHolidayReservationStatistics
				.setAppointmentNumberTwelve(labHolidayReservationStatistics12.getAppointmentNumberTwelve());
		list.add(labHolidayReservationStatistics);
	}

	private String getLockKey(String year) {
		return LabCourseTimetable.class.getClass() + year;
	}
	
	public static void main(String[] args){
		System.out.println(DateUtils.parseDate("2022-07-10").before(DateUtils.parseDate("2022-07-11")));
	}

}
